package com.ethan.cj.ssm.service.impl;

import com.ethan.cj.ssm.dao.CreditDao;
import com.ethan.cj.ssm.entity.Credit;
import com.ethan.cj.ssm.service.CreditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CreditServiceImpl implements CreditService {

    @Autowired
    private CreditDao creditDao;

    /**
     * 全部贷款信息分页查询
     *
     * @param page
     * @param limit
     * @return
     */
    @Override
    public Map<Object, Object> getCreditList(int page, int limit, Map<String, Object> map) {
        Map<Object, Object> result = new HashMap<>();
        int currentIndex = (page - 1) * limit;
        map.put("currentIndex", currentIndex);
        map.put("pageSize", limit);
        List<Credit> list = creditDao.getCreditList(map);
        int count = creditDao.getTotal(map);
        if (list != null && list.size() > 0) {
            System.out.println("123");
            result.put("code", 0);
            result.put("msg", "");
            result.put("data", list);
            result.put("count", count);
        } else {
            result.put("code", 1);
            result.put("msg", "无数据");
        }
        return result;
    }

    /**
     * 根据id和状态查看信息
     * @param cid
     * @param state
     * @return
     */
    @Override
    public Credit selectCreditCid(int cid, int state) {
        return creditDao.selectCreditCid(cid,state);
    }
}
